package com.zzu.base.controller.auth;

import com.zzu.base.common.pojo.ResultResponse;
import com.zzu.base.service.UserService;
import com.zzu.base.controller.auth.vo.LoginReqVO;
import com.zzu.base.controller.auth.vo.RegisterReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
@Tag(name = "认证")
public class AuthController {
    @Resource
    private UserService userService;
    @PostMapping("/login")
    @Operation(method = "登录",description = "用户登录接口")
    public ResultResponse<String> login(@Valid @RequestBody LoginReqVO loginReqVO) {
        return ResultResponse.success(userService.login(loginReqVO));
    }
    @PostMapping("/register")
    @Operation(method = "注册",description = "用户注册接口")
    public ResultResponse<Integer> register(@Valid @RequestBody RegisterReqVO registerReqVO) {
        return ResultResponse.success(userService.register(registerReqVO));
    }
    @Operation(method = "退出登录",description = "用户登出接口")
    @GetMapping("/logout")
    public ResultResponse<Boolean> logout(HttpServletRequest request, HttpServletResponse response) {
        return ResultResponse.success(userService.logout(request,response));
    }
}
